﻿''' vector.py 矢量数据可视化
'''
# 用Numpy数组表示向量
import numpy as np
# 箭头的位置
x, y, z = np.mgrid[0:1:20j, 0:1:20j, 0:1:20j]
# 给定位置的矢量元素
u = np.sin(np.pi*x) * np.cos(np.pi*z)
v = -2*np.sin(np.pi*y) * np.cos(2*np.pi*z)
w = np.cos(np.pi*x) * np.sin(np.pi*z) + np.cos(np.pi*y) * np.sin(2*np.pi*z)

from mayavi import mlab
#from mayavi.tools import pipeline
#src = mlab.pipeline.vector_field(u, v, w)
#mlab.pipeline.vectors(src, mask_points=20, scale_factor=3.0)

vectors = mlab.quiver3d(u,v,w)
vectors.glyph.mask_input_points = True
vectors.glyph.mask_points.on_ratio = 10
vectors.glyph.glyph.scale_factor = 2.0

mlab.outline()
mlab.show()